package com.lxl.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;

import com.lxl.service.BookClassifyService;
import com.lxl.service.impl.BookClassifyServiceImpl;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Font;
import java.awt.Cursor;

/**
 * @author 刘星鹭
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2014年9月12日 下午3:33:34
 */

public class MergeBookClassify extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField bookclassname_old;
	private JTextField bookclassname_new;
	private JLabel label_1;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MergeBookClassify frame = new MergeBookClassify();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public MergeBookClassify() {
		setFont(new Font("微软雅黑", Font.PLAIN, 12));
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {

				ViewBookClassify.main(new String[1]);

			}
		});
		setTitle("图书管理系统");
		setBounds(100, 100, 450, 205);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		bookclassname_old = new JTextField();
		bookclassname_old.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		bookclassname_old.setBounds(162, 24, 240, 27);
		contentPane.add(bookclassname_old);
		bookclassname_old.setColumns(10);

		bookclassname_new = new JTextField();
		bookclassname_new.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		bookclassname_new.setColumns(10);
		bookclassname_new.setBounds(162, 72, 240, 27);
		contentPane.add(bookclassname_new);

		JButton btnNewButton = new JButton("修改");
		btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				String name_new = bookclassname_new.getText();
				String name_old = bookclassname_old.getText();
				if (name_new.equals("") || name_old.equals(""))
					JOptionPane.showMessageDialog(null, "请填写所有资料！");
				else {
					BookClassifyService bookClassifyService = new BookClassifyServiceImpl();
					bookClassifyService.merge(name_old, name_new);
					JOptionPane.showMessageDialog(null, "修改成功！");
				}
			}
		});
		btnNewButton.setBounds(167, 124, 93, 23);
		contentPane.add(btnNewButton);

		JLabel label = new JLabel("请输入欲修改的类型名：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label.setBounds(20, 30, 138, 15);
		contentPane.add(label);

		label_1 = new JLabel("请输入新类型名：");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_1.setBounds(56, 78, 96, 15);
		contentPane.add(label_1);
	}
}
